import 'package:demo202112/utils/common_appbar.dart';
import 'package:flutter/material.dart';

/// @Author wywinstonwy
/// @Date 2022/1/19 11:21 下午
/// @Description: 

class MyScrollcontroller2 extends StatefulWidget {
  const MyScrollcontroller2({Key? key}) : super(key: key);

  @override
  _MyScrollcontroller2State createState() => _MyScrollcontroller2State();
}

class _MyScrollcontroller2State extends State<MyScrollcontroller2> {
  String _progress ='0%';
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: getAppBar("滚动监听"),
      body: NotificationListener<ScrollNotification>(
        onNotification: (ScrollNotification notification){
          double progress = notification.metrics.pixels/notification.metrics.maxScrollExtent;

          //重新构建
          setState(() {
            _progress ='${(progress*100).toInt()}%';
          });
          print("BottomEdge: ${notification.metrics.extentAfter == 0}");
          return false;          //return true; //放开此行注释后，进度条将失效
        },
        child: Stack(
          alignment: Alignment.center,
          children: [
            ListView.builder(
              itemCount: 100,
                itemExtent: 50,
                itemBuilder: (context,index){
                return ListTile(title: Text('$index'),);

                }),
            CircleAvatar(
              radius: 30,
              child: Text(_progress),
              backgroundColor: Colors.black54,
            )
          ],
        ),
      ),
    );
  }
}
